package com.tianyi.sfzy1.controller;

import com.tianyi.sfzy1.service.MemberpointsService;
import com.tianyi.sfzy1.util.R;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/memberpoints")
public class MemberpointsController {
    @Autowired
    private MemberpointsService memberpointsService;
//    插入积分
    @PostMapping("/insertPointsByMemberId")
    public R insertPointsByMemberId(int memberId, int points) {
        int i = memberpointsService.insertPointsByMemberId(memberId, points);
        if (i > 0) {
            return R.ok();
        } else {
            return R.fail("插入失败");
        }
    }

//    根据会员编号修改积分
    @PutMapping("/updatePointsByMemberId")
    public R updatePointsByMemberId(int memberId, int points) {
        int i = memberpointsService.updatePointsByMemberId(memberId, points);
        if (i > 0) {
            return R.ok();
        } else {
            return R.fail("修改失败");
        }
    }

//    根据会员编号删除积分
    @DeleteMapping("/deletePointsByMemberId")
    public R deletePointsByMemberId(int memberId) {
        int i = memberpointsService.deletePointsByMemberId(memberId);
        if (i > 0) {
            return R.ok();
        } else {
            return R.fail("删除失败");
        }
    }

    //根据会员编号删除积分(批量删除)
    @DeleteMapping("/deletePointsByIds")
    public R deletePointsByIds(@RequestBody List<Integer> memberId) {
        int i = memberpointsService.deletePointsByIds(memberId);
        if (i > 0) {
            return R.ok();
        } else {
            return R.fail("删除失败");
        }
    }
}
